package com.click.app.model;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * @author Joel Chuca Condo
 * @date 02/04/2009
 */
@Entity
@Table(name="size_ranks")
public class SizeRank extends BaseObject {
    
    private Long id;
    private String name;
    private String description;
    private String rank;
    private Set<ModelSize> modelSizes = new HashSet<ModelSize>();

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_size_rank")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name="name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="rank")
    public String getRank() {
        return rank;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name="numeration",
            joinColumns = { @JoinColumn( name="id_size_rank") },
            inverseJoinColumns = @JoinColumn( name="id_model_size")
    )
    public Set<ModelSize> getModelSizes() {
        return modelSizes;
    }

    public void setModelSizes(Set<ModelSize> modelSizes) {
        this.modelSizes = modelSizes;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SizeRank)) {
            return false;
        }
        SizeRank other = (SizeRank) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.SizeRank[id=" + id + "]";
    }

}
